<?php
require_once 'interface.php';
class mTalentPool
{
    use \control\interfaces;

    public string $date;
    public string $time;
    /**
     * 执行
     */

    public function __construct()
    {
        // 启用扩展
        $this->init();
        $this->date = date('Y-m-d');
        $this->time = date('Y-m-d H:i:s');
    }
    public function marryOption(): array
    {
        return  ['未婚'=>L('staffProfiles.table.unmarried'), '已婚'=>L('staffProfiles.table.married'), '离异'=>L('staffProfiles.table.divorce')];
    }

    private function head($title = ""): string
    {
        $root = root;
        $version = version;
        $css = <<<EOT
	<link href="{$root}static/stylesheet/animate.min.css?v=$version" rel="stylesheet">
		<link href="{$root}static/stylesheet/m.css?v=$version" rel="stylesheet">
EOT;
        $js = <<<EOT
	<script src="{$root}static/javascript/js.js?v=$version"></script>
EOT;
        $meta = "
	<meta name='viewport' content='width=device-width,initial-scale=1.0,viewport-fit=cover'>
	<meta name='apple-mobile-web-app-capable' content='yes'>
	<meta name='apple-mobile-web-app-status-bar-style' content='black'>
	<meta name='format-detection' content='telephone=no,email=no,adress=no'>
		";
        if (empty($title)) {
            $title = para("title");
        }
        $keywords = para("keywords");
        $description = para("description");
        return <<<EOT
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<meta name="keywords" content="$keywords">
	<meta name="description" content="$description">
	<title>$title</title>
$meta $css
	<link href="{$root}favicon.ico?v=$version" rel="Bookmark">
	<link href="{$root}favicon.ico?v=$version" rel="icon">
	<link href="{$root}favicon.ico?v=$version" rel="shortcut icon">
	<link href="{$root}favicon.ico?v=$version" rel="apple-touch-icon">
	<script src="{$root}static/javascript/jquery-1.11.2.min.js?v=$version"></script>
	<script src="{$root}static/javascript/lib.js?v=$version"></script>
	<script src="{$root}static/plugins/laydate/laydate.js?v=$version"></script>
$js
	<script>
	let root = '$root';
	</script>
</head>
<body>

EOT;
    }

    /*底部*/
    private function footer(): string
    {
        return <<<eof
<script>

function commitForm(form, url){
    //防止高频点击
    let finger = 2;
    if (finger === 2) {
        //串联表单
        var formName = form.split(",");
        var serialize = "";
        var a = "";
        for (var i = 0; i < formName.length; i++) {
            if (serialize === "") {
                a = "";
            } else {
                a = "&";
            }
            if (formName[i] !== "") {
                serialize += a + $("[name=" + formName[i] + "]").serialize();
            }
        }
        //异步提交数据
        $.post(url, serialize, function (data) {
            //console.log(data);
            if (data.code==1) {
                location.href = root+'control/mSuccess.html';
            } else {
                msg(data.warn, 'error');
            }
        }, "json");
    }
}
function msg(text, type = 'info') {
    return $.Toast(text, type, {
        fullscreen: false,
        timeout: 2000,
        progress: true,
        positionClass: "toast-top-right",
    });
}
 function getBirthDay(e){
        let IdCard = e.value;
        let birthDay = $("[name='birthDay']").val();
        if (IdCard.length ===18 && !birthDay){
            //获取出生日期
            $("[name='birthDay']").val(IdCard.substring(6, 10) + "-" + IdCard.substring(10, 12) + "-" + IdCard.substring(12, 14))
        }
    }
</script>

</body>
		</html>
eof;

    }

    /*返回*/
    public function indexHtml(): string
    {
        $html = $this->contentHtml();
        //返回
        return $this->head() . $html .$this->footer();
    }

    private function contentHtml(): string
    {

        $birthDateText = text(array('name'=>'birthDay','laydate'=>[],'other'=>"readOnly",'class'=>'text-input','title'=>L('staffProfiles.table.choose')));
        $workDateText = text(array('name'=>'workInDate','laydate'=>[],'other'=>"readOnly",'class'=>'text-input','title'=>L('staffProfiles.table.choose')));
        $downIco = root.'img/control/down_arrow.svg';
        $sex = radio(array('name'=>'sex','value'=>['男'=>L('staffProfiles.table.male'),'女'=>L('staffProfiles.table.female')],'checked'=>''));
        $education = select(array('name' => 'education', 'title' => L('staffProfiles.table.choose'), 'class' => 'not-arrow text-input',  'option' => explode('，', para('education'))));
        $nation=select(array('name' => 'nation', 'title' => L('staffProfiles.table.choose'), 'class' => 'not-arrow text-input',  'option' => explode('、', para('nationOption'))));
        $homeTown=repeatSelect(array('name' => 'homeTown', 'class' => 'not-arrow text-input',  'title' => L('staffProfiles.table.choose'), 'sqlForm' => 'region', 'sqlField' => 'province'));
        $marriage=radio(["name" => "marriage", 'value' => $this->marryOption()]);
        $politicsStatus=select(array('name' => 'politicsStatus', 'title' => L('staffProfiles.table.choose'),  'class' => 'not-arrow text-input',  'option' => explode('，', para('politicsStatus'))));
        $exSalary=select(array('name' => 'exSalary', 'title' => L('staffProfiles.table.choose'),  'class' => 'not-arrow text-input',  'option' => explode('，', para('exSalary'))));
        $exWorkPlace=select(array('name' => 'exWorkPlace', 'title' => L('staffProfiles.table.choose'),  'class' => 'not-arrow text-input', 'option' => explode('，', para('exWorkPlace'))));
        $jobId=idSelect([
            "name" => "jobId",
            "title" => L('staffProfiles.table.choose'),
            'sqlField' => 'name',
            'sqlId' => 'id',
            'sqlForm' => "job order by orderNo desc ",
            'class' => 'not-arrow text-input',
        ]);
        $title = L('staffProfiles.table.interview');
        $nameText = L('staffProfiles.table.name');
        $sexText =  L('staffProfiles.table.sex');
        $telText =  L('staffProfiles.table.tel');
        $idCardText =  L('staffProfiles.table.idCard');
        $birthDayText =  L('staffProfiles.table.birthDay');
        $nationText =  L('staffProfiles.table.nation');
        $homeTownText =  L('staffProfiles.table.homeTown');
        $educationText =  L('staffProfiles.table.education');
        $majorText =  L('staffProfiles.table.major');
        $workInDateText =  L('staffProfiles.table.workInDate');
        $collegeText =  L('staffProfiles.table.college');
        $marriageText =  L('staffProfiles.table.marriage');
        $politicsStatusText =  L('staffProfiles.table.politicsStatus');
        $addressText =  L('staffProfiles.table.address');
        $expect_addressText =  L('staffProfiles.table.expect_address');
        $expect_salaryText =  L('staffProfiles.table.expect_salary');
        $jobNameText =  L('staffProfiles.table.jobName');
        $saveTip =  L('staffProfiles.table.saveTip');
        $saveBtn =  L('staffProfiles.table.save');
        $writeTitle = L('staffProfiles.table.writeTitle');
        return <<<eof
<div class="body-content">
      <!-- 状态栏 -->
      <div class="topbar">
        <div class="topbar-text">$title</div>
      </div>
      <div class="content-parent">
     
      <div style="height: 44px"></div>
         <form name="talentForm">
        <div class="row-li">
            <div class="row-li-title"><span class="red-start">*</span>$nameText</div>
            <div class="row-li-value"><input name="name" type="text" placeholder="$writeTitle" value="" class="text-input"></div>
        </div>
        <div class="row-li">
            <div class="row-li-title"><span class="red-start">*</span>$sexText</div>
            <div class="row-li-value">$sex</div>
        </div>
        <div class="row-li">
            <div class="row-li-title"><span class="red-start">*</span>$telText</div>
            <div class="row-li-value"><input name="tel" type="text" placeholder="$writeTitle" value="" class="text-input"></div>
        </div>
        <div class="row-li">
            <div class="row-li-title">$idCardText</div>
            <div class="row-li-value"><input name="idCard" onblur="getBirthDay(this)" type="text" placeholder="$writeTitle" value="" class="text-input"></div>
        </div>
         <div class="row-li">
            <div class="row-li-title">$birthDayText</div>
            <div class="row-li-value">$birthDateText<img class="row-li-icon" src="$downIco"></div>
        </div>
         <div class="row-li">
            <div class="row-li-title">$nationText</div>
            <div class="row-li-value">$nation<img class="row-li-icon" src="$downIco"></div>
        </div>
         <div class="row-li">
            <div class="row-li-title">$homeTownText</div>
            <div class="row-li-value">$homeTown<img class="row-li-icon" src="$downIco"></div>
        </div>
         <div class="row-li">
            <div class="row-li-title"><span class="red-start">*</span>$educationText</div>
            <div class="row-li-value">$education<img class="row-li-icon" src="$downIco"></div>
        </div>
         <div class="row-li">
            <div class="row-li-title">$majorText</div>
            <div class="row-li-value"><input name="major" type="text" placeholder="$writeTitle" value="" class="text-input"></div>
        </div>
         <div class="row-li">
            <div class="row-li-title">$collegeText</div>
            <div class="row-li-value"><input name="college" type="text" placeholder="$writeTitle" value="" class="text-input"></div>
        </div>
         <div class="row-li">
            <div class="row-li-title">$workInDateText</div>
            <div class="row-li-value">$workDateText<img class="row-li-icon" src="$downIco"></div>
        </div>
         <div class="row-li">
            <div class="row-li-title">$marriageText</div>
            <div class="row-li-value">$marriage</div>
        </div>
         <div class="row-li">
            <div class="row-li-title">$politicsStatusText</div>
            <div class="row-li-value">$politicsStatus<img class="row-li-icon" src="$downIco"></div>
        </div>
         <div class="row-li">
            <div class="row-li-title">$addressText</div>
            <div class="row-li-value"><input name="liveAddress" type="text" placeholder="$writeTitle" value="" class="text-input"></div>
        </div>
        <div class="line-bar"></div>
         <div class="row-li">
            <div class="row-li-title"><span class="red-start">*</span>$jobNameText</div>
            <div class="row-li-value">$jobId<img class="row-li-icon" src="$downIco"></div>
        </div>
         <div class="row-li">
            <div class="row-li-title">$expect_addressText</div>
            <div class="row-li-value">$exWorkPlace<img class="row-li-icon" src="$downIco"></div>
        </div>
         <div class="row-li">
            <div class="row-li-title">$expect_salaryText</div>
            <div class="row-li-value">$exSalary<img class="row-li-icon" src="$downIco"></div>
        </div>
        </form>
        <div class="row-li">
         <span class="red-start">*</span><span>$saveTip</span>
        </div>
      </div>
      <div class="text-button" onclick="commitForm('talentForm',root+'interface/v1/index.php?cla=talentApp&fun=commitEdit')">$saveBtn</div>
    </div>
eof;
    }

}

//实例化对象
$mTalentPoolClass = new mTalentPool();
//打印结果
echo $mTalentPoolClass->indexHtml();

